Skip to content

fix: surface unrouted / unrecognized-path requests instead of going silent (#1290) - #1291

Merged
ranxianglei merged 4 commits into
masterfrom
2026-09-25_surface-unrouted-endpoints
Sep 25, 2026
Merged

ranxianglei merged 4 commits into
masterfrom
2026-09-25_surface-unrouted-endpoints

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

#1290: with dsh + the dsh-commandcode-provider plugin's Go plan, model calls go to a custom wire (POST /alpha/generate) whose path matches none of bili's known protocol suffixes. bili relayed those bytes through and compressed nothing — and told the user nothing, contradicting the #1158 "tell me why it didn't compress" promise and the #897 loud-not-silent principle.

This PR makes that outcome loud at both ends so a user can see why a request wasn't compressed instead of guessing. It does not make the custom wire compressible (that is a separate feature — see below).

Changes

Client side (was the silent direct-connect gate):

  • src/agent/native-intercept.ts: new optional NativeInterceptState.onUnroutedModelUrl(url) hook, fired for every request the fetch patch lets through without routing because its URL misses isModelApiUrl. Undefined hosts stay silent → zero behavior change for other clients.
  • src/agent/dsh-native.ts: wires the hook to log each distinct unrouted endpoint once per process via console.error + persistClientEvent (the durable channel GUI hosts need), bounded at 256 distinct endpoints like the existing gateRefusals.

Proxy side (was warn-3-times-then-silence):

  • src/server/observability.ts: getUnrecognizedPathStats() aggregates the existing per-path warn map.
  • src/server.ts: /__bili/stats gains an unrecognizedPaths field (total + per-path counts).
  • src/acp-status.ts: acp_status gains an UNRECOGNIZED PATHS (instance-level) section while such requests exist, mirroring the existing UNDECRYPTED TRAFFIC section.

Docs: README troubleshooting section explaining the limitation, the three new signals, and the workaround (use the provider's standard protocol endpoint — Command Code's Provider plan posts to /provider/v1/chat/completions, which does compress).

Behavior change (intended, flagged per house rule)

surface old new
client, non-model-API URL went direct silently each distinct endpoint logs once per process (console.error + persistClientEvent, ≤ 256 distinct)
/__bili/stats { sessions, blindTunnels } adds unrecognizedPaths
acp_status no path section adds UNRECOGNIZED PATHS section only when count > 0

Additive only — no threshold/default/timing/existing-output-format changed; no fallback or default value changed.

Not done here (P2 — needs owner decision)

Actually compressing a custom wire requires a new codec (request decoder from the CLI envelope params.messages + JSONL response decoder) plus a config seam to declare a 5th wire. That touches BOTH compression modes' wire/message shape and the config schema → stays a human-scoped feature per §7.4. Recommended interim: the loud signal (this PR) + the Provider-plan workaround.

Pre-flight (rebased onto current master 8e5eb58)

  • npm run typecheck — clean
  • npm run build — success (+ dist-import-annotations: OK)
  • npm test — 2494 pass / 0 fail / 9 skipped (skips are env-gated claude-native e2e behind ACP_TEST_CLAUDE_NATIVE)
  • Regression tests: tests/native-intercept.test.ts (hook fires for a custom wire, not for a routed model endpoint) + tests/dump-observability.test.ts (per-path counts exposed).

Rebased onto current master; single conflict in the src/server.ts import line resolved by union (kept upstream's new output-steering import + this change's getUnrecognizedPathStats).

Partially addresses #1290.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-25_surface-unrouted-endpoints (e3086d3)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1291

Each push to this PR publishes a new version under the pr-1291 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1291.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review of PR #1291 — reviewed against current master (8e5eb582, verified up-to-date, no rebase needed), ran the full pre-flight locally, found and directly fixed two small issues on the branch (commits below), and re-verified green.

① Original issue (direction gate)

#1290's root cause was established in triage: protocol detection is path-suffix tables on both ends (client isModelApiUrl, proxy suffix table), no seam for custom wires, and both sides went silent. This PR correctly scopes P1 = observability only: it makes the "went direct, never compressed" outcome visible at both ends without touching compression semantics or wire bytes. P2 (actually compressing a custom wire = new codec + config seam, touches both modes' message shape + config schema → §7.4 human-scoped) stays out, with the three options left open in #1290 for owner decision. Direction is right.

② Regression review (existing behaviors touched)

Walked every direct-send path through the patched fetch and every surface the diff touches:

existing behavior verdict
non-model URLs pass through byte-unmodified (return orig(input, init)) preserved — routing logic untouched
hosts without the hook (pi/opencode/omp/…) zero change — hook is optional, ?. call
model-API URLs refused by the attribution gate (#1158) untouched — they keep their own gateRefusals channel; the new hook fires only on !isModelApiUrl, no overlap
model-API URLs sent direct on bootstrap failure untouched — keep the existing "proxy not ready" warn
/__bili/stats response shape additive field only; loopback-only endpoint; consumers read named fields, no strict schema
acp_status output unchanged while count = 0; section mirrors the existing UNDECRYPTED TRAFFIC block (top-10 by count, gated on total > 0)
logUnrecognizedPath warn×3→suppress behavior untouched — getUnrecognizedPathStats() is a pure read of the same map
thresholds / defaults / timing / fallbacks / config schema / persistence format / wire or message shape (both modes) none changed

All disclosed behavior changes match the code exactly (client: silent direct → once-per-process-per-endpoint log, ≤256 distinct; stats: +unrecognizedPaths; acp_status: +section).

③ Code review — two findings, both fixed directly on the branch

F1 (fixed, commit 4e4ca1a3) — the hook fired for bili's own control-plane URLs. /__bili/plugin/manifest, /__acp/*, and un-routable /bili/<protocol>/<url> shapes all miss isModelApiUrl by design, and they reach the hook site (the self-origin guard sits after it, and dsh fetches the manifest via global fetch at bootstrap — src/agent/shared.ts:88). Result: every dsh boot would log/persist "…/__bili/plugin/manifest is not a recognized model endpoint, so bili did not route it through the proxy" — factually wrong (that URL IS the proxy) and noise that dilutes the exact signal this PR creates. Fix: isBiliControlUrl() guard at the hook site in src/agent/native-intercept.ts (path knowledge lives there, so future hosts inherit correct semantics); test extended to assert control-plane URLs do NOT fire.

F2 (fixed, commit 813e126f) — the new README troubleshooting section had no mirror in README.zh-CN.md, violating the zh/en sync rule (§7.3). Added the corresponding subsection after the zh http.proxy section. CONFIGURATION.md intentionally untouched: no env var or config surface involved (purely informational signals), consistent with how §7.3 scopes doc mirroring.

Otherwise clean: stats keys use query-stripped + maskUrlsInText (same key semantics as the rate limiter, so counts can't split on varying queries); the dsh dedup key strips query/hash the same way; the 256-cap freezes rather than resets like gateRefusals.clear() — acceptable, since re-reporting cleared endpoints would spam the durable event channel. console.error in dsh-native.ts is agent-side (client process), matching the file's existing pattern — not a server-module violation.

④ Test validity

  • tests/native-intercept.test.ts: real teeth — asserts the custom wire went direct AND the model endpoint got routed, hook fires exactly twice (per-request, host dedups), and (my extension) control-plane URLs never fire. Verified the extended assertion catches the F1 bug: pre-fix it fails 4 !== 2.
  • tests/dump-observability.test.ts: counts under the masked key increment exactly by 5, using the production key derivation.
  • Both pin the new behavior; the original defect (zero signal) cannot recur silently.

⑤ Diff cleanliness

8 files, +115/−5, every line serves the PR's purpose; the single import-line conflict was resolved by union correctly; no whitespace churn, no lockfile/generated churn. My two follow-up commits are small and separately labeled.

Verification (re-run after my fixes)

  • npm run typecheck — clean · npm run build — success (+ dist-import-annotations: OK)
  • npm test — 2494 pass / 0 fail / 9 skipped (skips = ACP_TEST_CLAUDE_NATIVE-gated e2e, matches the PR's claim)
  • CI on head 813e126f: running (4 test jobs in progress across ubuntu/windows × node 22/24; version-guard completed). Local results above are the same gates CI runs.

Verdict: mergeable once CI goes green — human merges. P2 (custom-wire compression) remains an open decision in #1290; nothing here precludes any of the three options.

中文摘要:审查了本 PR(让未识别端点"直连不压缩"不再静默),方向和实现都正确;直接在分支上补了两个小修——①钩子误把 bili 自身控制面 URL(/__bili/、/__acp/、/bili/)报成"未识别端点",已加排除守卫并补测试;②新排障小节漏了 README.zh-CN.md 镜像,已补。typecheck/build/全量测试(2494 过 0 挂)本地全绿,CI 运行中,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI confirmed green on head 813e126f (includes both review-fix commits): all checks success — test matrix (ubuntu/windows × node 22/24), version-guard, both zero-token e2e lanes (codex, pi), build-artifact.

Verdict stands: ready for human merge. P2 (custom-wire compression) remains an open decision in #1290.

中文摘要:CI 全绿(含两个审查补修提交),本 PR 可合并。

ework-agent added 3 commits September 25, 2026 11:48
…ilent (#1290)

A request whose path matches no known wire protocol (e.g. a third-party
plugin's custom wire such as commandcode's Go plan POST /alpha/generate) was
relayed byte-for-byte with ZERO signal — neither compression nor any
explanation. That contradicts the #1158 "tell me why it didn't compress"
promise and the #897 loud-not-silent principle. Make both ends loud.

Client (native-intercept + dsh-native):
- New optional NativeInterceptState.onUnroutedModelUrl hook, fired for every
  request the fetch patch lets through WITHOUT routing because its URL misses
  isModelApiUrl. Undefined hosts stay silent (no behavior change for others).
- dsh wires it to log each distinct unrouted endpoint once per process via
  console.error + persistClientEvent (the durable channel GUI hosts need),
  bounded at 256 distinct endpoints like gateRefusals.

Proxy (server/observability + server + acp-status):
- getUnrecognizedPathStats() aggregates the existing per-path warn map.
- /__bili/stats gains an `unrecognizedPaths` field (count + per-path counts).
- acp_status gains an "UNRECOGNIZED PATHS (instance-level)" section while such
  requests exist, mirroring the UNDECRYPTED TRAFFIC section.

Docs: README troubleshooting section explaining the limitation + the new
signals + the workaround (use the provider's standard protocol endpoint).

Behavior change (intended): non-model-API URLs previously went direct silently;
each such endpoint now logs once per process. /__bili/stats and acp_status gain
additive fields/sections. No existing threshold/default/timing/output-format
changed. This does NOT make custom wires compressible — that is a separate
feature (custom request/response codec + config seam) pending owner decision.

Regression tests: native-intercept (hook fires for a custom wire, not for a
routed model endpoint) + dump-observability (per-path counts exposed).
@ranxianglei
ranxianglei merged commit 897c9d7 into master Sep 25, 2026
9 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-25_surface-unrouted-endpoints branch October 15, 2026 05:32
ranxianglei pushed a commit that referenced this pull request Oct 20, 2026
…cp_status + panel

Custom-wire endpoints (e.g. TRAE llm_utils_chat / Qoder sash agent_chat_generation)
go DIRECT at the host and never reach the proxy, so the server-side unrecognizedPaths
stat (#1290/#1291) is blind to them. Add a host->proxy report (/__bili/plugin/unrouted,
fire-and-forget on first sighting of each distinct endpoint) and surface the set where
users already look: the acp_status/compress unknown-conversation 404 now NAMES the
endpoints instead of staying generic, and the web panel shows a dedicated banner.

Pure diagnostics: no compression behavior, threshold, default, data-format, or config
change. Inputs bounded (per-path length + count cap); latest report wins per agent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant